package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.model.admin.dtos.ChannelDTO;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理", tags = "channel", description = "频道管理API")
public class AdChannelController {
    @Autowired
    AdChannelService adChannelService;
    /**
     * 频道名称分页列表查询
     * @param dto
     * @return
     */
        @PostMapping("/list")
        @ApiOperation("频道分页列表查询")
        public ResponseResult findByNameAndPage(@RequestBody ChannelDTO dto){
            return  adChannelService.findByNameAndPage(dto);
        }

    /**
     * 新增频道
     * @param adChannel
     * @return
     */
        @PostMapping("/save")
        @ApiOperation("新增频道")
    public ResponseResult insert(@RequestBody AdChannel adChannel){
            return adChannelService.insert(adChannel);
        }

    /**
     * 根据id删除指定频道
     * @param id
     * @return
     */
    @ApiOperation("删除频道")
    @GetMapping("/del/{id}")
    public ResponseResult delete(@PathVariable("id") Integer id){
            return  adChannelService.deleteById(id);
     }

    /**
     * 更新频道
     * @param adChannel
     * @return
     */
     @ApiOperation("更新频道")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody AdChannel adChannel){
        return adChannelService.update(adChannel);
     }

    @ApiOperation("查询全部频道")
    @GetMapping("/channels")
    public ResponseResult findAll() {
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }

    @ApiOperation("根据id查询频道")
    @GetMapping("/one/{id}")
    public ResponseResult findOne(@PathVariable Integer id) {
        return ResponseResult.okResult(adChannelService.getById(id));
    }
}
